package com.baseframe.match.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baseframe.match.entity.SnsMatch;
import com.baseframe.match.entity.request.SnsMatchRequest;
import com.baseframe.match.entity.vo.SnsMatchVO;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 数据库操作Mapper，用于对【sns_match】表进行操作
 *
 * @Entity com.baseframe.blog.entity.SnsMatch
 */
public interface SnsMatchMapper extends BaseMapper<SnsMatch> {

    /**
     * 获取最新的竞赛列表
     *
     * @return 返回最新的竞赛列表
     */
    @Select("select * from sns_match where is_deleted = 0 order by create_time desc limit 8")
    List<SnsMatchVO> gerNewList();

    /**
     * 分页查询竞赛列表
     *
     * @param page    分页对象
     * @param request 请求对象，包含查询条件
     * @return 返回竞赛信息的分页结果
     */
    @Select("<script>" +
            "select sm.*,bu.username as publisher_name from sns_match as sm left join base_user as bu on sm.create_by"
            + " = bu.id" +
            "<where>" +
            "sm.is_deleted = 0 " +
            "<if test=\" request.title!=null &amp;&amp; request.title !='' \">" +
            "and sm.title like concat('%',#{request.title},'%')" +
            "</if>" +
            "</where>" +
            "order by sm.create_time desc" +
            "</script>")
    Page<SnsMatchVO> matchPageList2Front(Page<SnsMatchVO> page, @Param("request") SnsMatchRequest request);

    /**
     * 根据竞赛ID获取竞赛详细信息
     *
     * @param id 竞赛ID
     * @return 返回竞赛的详细信息
     */
    @Select("select sm.*,bu.username as publisher_name from sns_match as sm left join base_user as bu on sm.create_by"
            + " = bu.id where bu.is_deleted = 0 and sm.id = #{id}")
    SnsMatchVO getDetailsById(@Param("id") Long id);
}
